<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.DriverManager"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>根据首字查成语</title>
<style type="text/css">
h1,b{color:red;}
</style>
</head>
<body>
<h1>根据首字查成语</h1>
<%
String first=request.getParameter("firstWord");
String sql="select * from chengyu where first=?";
String showSql="select * from chengyu where first='<b>"+ first+"</b>'";
%>
<p><%=showSql %></p>
<p>以【<b><%=first %></b>】开头的成语如下：</p>
<%
Class.forName("com.mysql.cj.jdbc.Driver");
try(Connection cn=DriverManager.getConnection("jdbc:mysql://localhost:3306/db?allowMultiQuerise=true","root","12qwas");
		PreparedStatement ps=cn.prepareStatement(sql);){
	ps.setString(1,first);
	try(ResultSet rs=ps.executeQuery()){
		while(rs.next()){
			String cy=rs.getString("cy");
			out.println(cy+" ");
		}
	}
}
		
%>
</body>
</html>